package com.neusoft.hospital.controller;

import com.neusoft.hospital.pojo.checkitem;
import com.neusoft.hospital.pojo.checkitemdetailed;
import com.neusoft.hospital.service.Checkitemservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin(origins = "*" ,allowCredentials = "true")
@RequestMapping("/chk")
public class ChkController {
    @Autowired
    Checkitemservice checkitemservice;


//===================================================select option========================================================

    /*	select cireport全部数据列表
     *
     */
    @RequestMapping("/AllchkList")
    public Map<String, Object> AllCirList() throws Exception{
        List<checkitem> cirList = checkitemservice.findcheckitemBySql();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("status", "1");
        map.put("cirList", cirList);
        return map;
    }

    /*	select cireport 模糊查询
     * 	http://localhost:8080/chk/getchkByName?ciName=血
     */
    @RequestMapping("/getchkByName")
    public Map<String, Object> getCirByName(HttpSession session,checkitem checkitem) throws Exception{
        List<checkitem> checkitemList = checkitemservice.findCheckitemByChoose(checkitem);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("status", "1");
        map.put("chkList", checkitemList);
        return map;
    }

    /*	select cireport by cirId
    * 	http://localhost:8080/chk/getchkByciId?ciId=1
     */
    @RequestMapping("/getchkByciId")
    public Map<String, Object> getCirByciId(int ciId) throws Exception{
        List<checkitem> checkitemList = checkitemservice.findCheckitemList2(ciId);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("status", "1");
        map.put("chk", checkitemList);
        return map;
    }

//===================================================insert============================================================

   /*	数据库的增加操作
    * 	http://localhost:8080/chk/Insetchk?ciId=12&ciName=嘎嘎嘎
     */
@RequestMapping("/Insetchk")
public Map<String, Object> Insetchkd(HttpSession session, checkitem checkitem) throws Exception{
    int ciId = checkitem.getCiId();
    int count = checkitemservice.insertCheckitem(checkitem);
    Map<String, Object> map = new HashMap<String, Object>();
    if(count>0){
        map.put("status", "1");
    } else {
        map.put("status", "0");
    }
    return map;
}



//    //===================================================update============================================================
    /*	update
     * http://localhost:8080/chk/doUpdate?ciId=12&ciName=哥哥哥哥
     */
    @RequestMapping("/doUpdate")
    public Map<String, Object> doUpdate(checkitem checkitem, String enable) throws Exception{
        checkitemservice.updatecheckitem(checkitem);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("status", "1");
        return map;
    }
    //===================================================delete============================================================
    /*	delete
     * http://localhost:8080/chk/delByciId?ciId=11
     */
    @RequestMapping("/delByciId")
    public Map<String, Object> delByciId(HttpSession session, checkitem checkitem ) throws Exception{
        int count = checkitemservice.deletecheckitem(checkitem);
        Map<String, Object> map = new HashMap<String, Object>();
        if(count>0){
            map.put("status", "1");
        } else {
            map.put("status", "0");
        }
        return map;
    }
}
